/**
 * Token.java
 *
 * @author: ZhuJiahui
 * @date: 2018/7/26 23:44
 */
package com.zhujiahui.nlp.core.domain;

/**
 * @description:
 * @author: ZhuJiahui
 * @version: 1.0
 */
public class Token implements Cloneable {
    // 词汇
    private String word;

    // 词性标注
    private String pos;

    // 默认值设置
    public static final String DEFAULT_WORD = "WORD_NULL";

    public static final String DEFAULT_POS = "POS_NULL";

    // toString方法的分隔符
    public static final String DELIMITER = "||";

    /**
     * 默认构造方法
     */
    public Token() {
        this.word = DEFAULT_WORD;
        this.pos = DEFAULT_POS;
    }

    /**
     * 带参数的构造函数
     *
     * @param word
     *            词汇
     * @param pos
     *            词性
     */
    public Token(String word, String pos) {
        super();
        this.word = word;
        this.pos = pos;
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((pos == null) ? 0 : pos.hashCode());
        result = prime * result + ((word == null) ? 0 : word.hashCode());
        return result;
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;

        Token other = (Token) obj;
        if (pos == null) {
            if (other.pos != null)
                return false;
        } else if (!pos.equals(other.pos))
            return false;

        if (word == null) {
            if (other.word != null)
                return false;
        } else if (!word.equals(other.word))
            return false;

        return true;
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#clone()
     */
    @Override
    public Object clone() {
        Token clonedToken = null;
        try {
            clonedToken = (Token) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return clonedToken;
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.word);
        sb.append(Token.DELIMITER);
        sb.append(this.pos);
        return sb.toString();
    }

    /**
     * ====================================================
     * 以下是get和set方法
     */

    /**
     * @return the word
     */
    public String getWord() {
        return word;
    }

    /**
     * @param word
     *            the word to set
     */
    public void setWord(String word) {
        this.word = word;
    }

    /**
     * @return the pos
     */
    public String getPos() {
        return pos;
    }

    /**
     * @param pos
     *            the pos to set
     */
    public void setPos(String pos) {
        this.pos = pos;
    }
}
